package com.java.multipledatasource.registered;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hu
 * @version 1.0
 * @date 2020/12/30 0030 下午 2:26
 * @description
 */
@RestController
@RequestMapping("/user")
public class RegisteredController {

    @Autowired
    private  CheckParamsService checkParamsService;

    @RequestMapping("/registered")
    public Result  registered(@RequestParam Object registerObj, @RequestParam byte registerType) throws Exception {
        this.checkParam(registerObj, registerType);
        // todo md5(password) and  insert
        return Result.success();
    }

    private void checkParam(Object obj, byte registerType) throws Exception {
        if (!RegisteredEnums.checkCode(registerType)) {
            throw new Exception("registerType error");
        }
        checkParamsService.checkByField(registerType, obj);
        checkParamsService.checkIsExit(registerType, obj);
    }
}
